#ifndef _VIDEO_TEST_H
#define _VIDEO_TEST_H

#include "CTestReport.h"
#include "Logger.h"
#include "radar_detect.h"
#include <QProcess>
#include <QStringList>
#include <QThread>
#include <QVector>
#include <qcontainerfwd.h>
#include <qobject.h>
#include <qtmetamacros.h>
#include <stdint.h>

class CThreadVideoTest : public QThread {
  Q_OBJECT

public:
  CThreadVideoTest(QWidget *parent){};
  ~CThreadVideoTest(){};

private:
  void ReadRadarDataFromFile(QString video_file, QVector<uint32_t> &radar_data);
  QString MakeLogFolder();
  QString GetMcuLogFileName(QString file_name);
  QString GetTestLogFileName(QString file_name);
  QString GetRadarChartFileName(QString file_name);
  void MakeAlgOutputFolder(QString file_name);
  void GenerateAlgParam(QString file_name, QStringList &args);
  void OnAlgResultProcess(QLogger &logger, int ret_code);
  int UpdateRadarData(QString file_name);

public:
  void SetStop(bool stop) { stop_ = stop; };
  bool stop_ = true;
  int SetFileList(QStringList list) {
    file_list_ = list;
    return 0;
  };
  int SetOutputFolder(QString Folder) {
    folder_output_ = Folder;
    return 0;
  };

public:
  QVector<uint32_t> radar_data_;
  int radar_index_;
  bool soc_on_;
  uint32_t soc_on_count_;
  SocTrigInfo_t soc_trig_info_;

private:
  QStringList file_list_;
  QString folder_output_;
  uint64_t radar_interval_;
  uint32_t trig_index_;
  bool has_car_;
  bool park_out_;
  uint64_t total_frames_;
  QVector<CTestReport::EventInfo_t> mark_info_;
  QVector<CTestReport::EventInfo_t> alg_resl_;
  uint8_t last_alg_resl_;
  uint32_t alg_wait_count_;

public:
  static int OnSocTrig(int soc_state, void *param);
  static int OnRadarTrig(uint16_t *dist, uint16_t *amp, void *param);
  void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
  uint64_t GetRadarInterval(QString video_file, uint32_t radar_num);
  int OnAlgResultProcess(QLogger &logger, QString cur_file);
  bool GetAlgResultFromMarkInfo(QVector<CTestReport::EventInfo_t> info,
                                uint32_t idx);
  int DoBeforeTest(QString file_name, CTestReport *report, QLogger &logger);
  int AddAlgResult(uint32_t id, uint8_t type);
  void StartAlgProc(QString file_name, QLogger &logger);
  int OnPowerOn(QLogger &logger);

protected:
  void run();
};

#endif